﻿using API.Base;
using Appliaction.IAppServices;
using Domain.Entitys;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class SystemHomeController : ControllerBase
    {
        private readonly ISystemHomeService systemHomeService;

        public SystemHomeController(ISystemHomeService systemHomeService)
        {
            this.systemHomeService = systemHomeService;
        }

        /// <summary>
        /// 查询业务单总数
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public JsonResult GetBusinessCounts()
        {
            return new JsonResult(systemHomeService.GetBusinessCounts());
        }

        /// <summary>
        /// 查询入库总数
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public JsonResult GetStoreCounts()
        {
            return new JsonResult(systemHomeService.GetStoreCounts());
        }

        /// <summary>
        /// 查询出库总数
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public JsonResult GetOutboundCounts()
        {
            return new JsonResult(systemHomeService.GetOutboundCounts());
        }

        /// <summary>
        /// 查询退货总数
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public JsonResult GetReturnCounts()
        {
            return new JsonResult(systemHomeService.GetReturnCounts());
        }

        [HttpPost]
        public FileResult ExportExcel(Execl execl)
        {
            var result = ExeclHelper.Export(execl.Headers, execl.Rows, execl.Title,execl.MergeColumns);
            return File(result, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",$"{execl.Title}.xlsx");
        }
    }
}
